<template>
  <div class="autumn-container">
    <!-- 面包 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/dashboard' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>系统日志</el-breadcrumb-item>
    </el-breadcrumb>

    <div class="autumn-center">
      <!-- 搜索栏 -->
      <div class="query-form">
        <autumn-search :modelValue="queryInfo" @search="search">
          <template #default>
            <el-col :span="4">
              <el-form-item prop="createName" label="操作员">
                <el-input v-model="queryInfo.createName" />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item prop="type" label="类型">
                <el-select v-model="queryInfo.type" placeholder="请选择">
                  <el-option v-for="(value, key, index) in operationTypes" :key="index" :label="value" :value="key">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </template>
        </autumn-search>
      </div>

      <!-- 数据表格 -->
      <div class="main-body top">
        <autumn-table :page="page" @changePage="search">
          <template #column>
            <el-table-column type="index" label="#" fixed="left" align="center">
              <template #default="scope">
                {{ initIndex(scope.$index) }}
              </template>
            </el-table-column>
            <el-table-column label="类型" width="80" align="center">
              <template #default="scope">
                <el-tag type="success" size="small" v-if="scope.row.type == 'ADD'">新增</el-tag>
                <el-tag type="warning" size="small" v-else-if="scope.row.type == 'UPDATE'">修改</el-tag>
                <el-tag type="danger" size="small" v-else-if="scope.row.type == 'DELETE'">删除</el-tag>
                <el-tag type="info" size="small" v-else>其它</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="target" width="150" label="操作目标" show-overflow-tooltip />
            <el-table-column prop="args" label="操作信息" show-overflow-tooltip />
            <el-table-column prop="ip" width="150" label="操作IP" show-overflow-tooltip />
            <el-table-column prop="uri" label="操作地址" show-overflow-tooltip />
            <el-table-column prop="createName" label="操作人" width="100" />
            <el-table-column prop="createTime" label="操作时间" width="150" align="center"
              :formatter="(row: any) => $moment(row.createTime, 'YYYY-MM-DD HH:mm')" />
          </template>
        </autumn-table>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from 'vue'
import hooks from 'src/hook/index'
import { $moment } from 'src/util/tools'
import { pageActionLog } from 'src/api/monitor/actionLog'

const operationTypes = reactive({
  ADD: '新增',
  UPDATE: '修改',
  DELETE: '删除'
})

// 分页查询
const queryInfo = reactive({
  createName: '',
  type: ''
})
const { page, initIndex, search } = hooks.useTable((pageNumber: number, pageSize: number) => {
  pageActionLog({ ...queryInfo, pageNumber, pageSize }).then(({ data }) => {
    page.data = data.list
    page.total = data.total
  })
})

</script>

<style lang="scss" scoped></style>
